<?php

namespace app\validate;

use think\Validate;

/**
 * 客户管理-注册单位/聘用单位/出证单位
 */
class UnitInfo extends Validate
{
    protected $rule = [
        'type|类型' => 'require|number|checkType',
        'aliasId|别名' => 'require',
        'page|页码' => 'require|number',
        'pageNum|每页条数' => 'require|number',
        'title|企业名称' => 'requireWith:title',
        'contacts|联系人' => 'requireWith:contacts',
        'mobile|联系电话' => 'requireWith:mobile',
        'area|所属区域' => 'requireWith:area',
        'area_level|区域等级' => 'requireWith:area|checkAreaLevel',
        'establish_start_date|成立时间开始' => 'requireWith:establish_start_date',
        'establish_end_date|成立时间结束' => 'requireWith:establish_end_date',
        'qualifications_type|资质类别' => 'requireWith:qualifications_type',
        'secure_expire_start_date|安全时间开始' => 'requireWith:secure_expire_start_date',
        'secure_expire_end_date|安全时间结束' => 'requireWith:secure_expire_end_date',
        'register_price|注册资金' => 'requireWith:register_price',
    ];

    protected function checkType($value)
    {
        $error = true;
        if (!in_array($value, [1, 2, 3])) {
            $error = '类型不在规定范围内';
        }
        return $error;
    }

    protected function checkAreaLevel($value)
    {
        $error = true;
        if (!in_array($value, [1, 2, 3])) {
            $error = '区域等级不在规定范围内';
        }
        return $error;
    }
}